<template>
	<view>
		<view class="jiaonang" :style="{height: navHeight, top: statusBarHeight, backgroundColor: bgcolor}">
			<view class="kb" :style="{width: navWidth}">
				<view class="logo" :style="{height: navHeight}" @click="toIndex">
					<image src="../../static/logo.png" mode="heightFix"></image>
				</view>
				<view class="search iconfont icon-sousuo" @click="toSearch"></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "jiaonang",
		data() {
			return {
				navHeight: "",
				navWidth: "",
				statusBarHeight: "",
				statusNav: ""
			};
		},
		props: {
			bgcolor: {
				type: String,
				default() {
					return "#fff"
				}
			}
		},
		methods: {
			toSearch() {
				uni.navigateTo({
					url: "../../pages/search/search"
				})
			},
			toIndex() {
				uni.switchTab({
					url: '/pages/index/index'
				});
			}
		},
		mounted() {
			// 胶囊高度
			let jnHeight = wx.getMenuButtonBoundingClientRect().height
			// 胶囊top
			let jnTop = wx.getMenuButtonBoundingClientRect().top
			
			this.statusBarHeight = getApp().globalData.statusBar + "px";
			
			// 导航栏高度 = 胶囊高度 + 外边距*2
			this.navHeight = jnHeight + (jnTop - getApp().globalData.statusBar) * 2 + "px"
			getApp().globalData.navHeight = jnHeight + (jnTop - getApp().globalData.statusBar) * 2

			this.navWidth = wx.getMenuButtonBoundingClientRect().left + "px";
			
			this.statusNav = getApp().globalData.statusBar + getApp().globalData.navHeight;
			getApp().globalData.statusNav = this.statusNav;
		}
	}
</script>

<style scoped lang="scss">
	.jiaonang {
		background-color: #ffffff;
		position: fixed;
		left: 0;
		z-index: 10;
		width: 100%;

		.kb {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-right: 10px;
			padding-left: 16rpx;
			box-sizing: border-box;

			.logo {
				image {
					height: 100%;
				}
			}
			
			.search {
				// background-color: #fff;
				font-size: 25px;
			}
		}
	}
</style>
